package com.base.cn.platform.os.controller.op.giftCard;

import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.manage.op.giftcard.OpGiftCardCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 礼品卡Controller接口
 *
 * @author s.li
 * @create 2018-08-30-14:13
 */
@RestController
@RequestMapping("/api/op")
public class ApiOpGiftCardController extends ApiBaseController {

    @Autowired
    private OpGiftCardCodeService opGiftCardCodeService;

    /**
     * 我的礼品卡列表
     * @param userId 用户ID
     * @param currentPage 页码
     * @return Map<String,Object>
     */
    @RequestMapping("/giftCardList")
    public Map<String,Object> giftCardList(@RequestParam("userId")BigDecimal userId,
                                           @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        HashMap<String, Object> giftCard = new HashMap<>();
        giftCard.put("userId",userId);
        giftCard.put("status",1);
        Map<String, Object> giftCardCodeListPage = opGiftCardCodeService.queryOpGiftCardCodeListPage(currentPage, giftCard, true, false,true);
        return ResultUtil.SUCCESS(giftCardCodeListPage);
    }

    /**
     * 激活礼品卡
     * @param userId 用户ID
     * @param code 礼品卡编码
     * @param codePwd 礼品卡密码
     * @param id 礼品卡ID
     * @return Map<String,Object>
     */
    @RequestMapping("/activateGiftCardCode")
    public Map<String,Object> activateGiftCardCode(@RequestParam("userId") BigDecimal userId,
                                                   @RequestParam("code") String code,
                                                   @RequestParam("codePwd") String codePwd,
                                                   @RequestParam("id") BigDecimal id){
        return opGiftCardCodeService.activateGiftCard(id,userId,code,codePwd);
    }
}
